/*******************************************************************
 *  Copyright(c) 2018-2018 A single spark
 *  All rights reserved.
 *
 *  文件名称:  yuvoperater.h
 *  简要描述:  提供yuv视频数据播放等相关功能
 *
 *  创建日期:  2018.03.12
 *  作者:     使徒保罗
 *  邮箱:     297329588szh@163.com
 *  说明:
 ******************************************************************/
#ifndef YUVOPERATER_H
#define YUVOPERATER_H

#include <QFile>
#include <QThread>
#include <QImage>

using namespace std;
extern "C"
{
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
    #include <libswscale/swscale.h>
    #include <libavdevice/avdevice.h>
    #include <libavformat/version.h>
    #include <libavutil/time.h>
    #include <libavutil/mathematics.h>
}


class yuvoperater:public QThread
{
    Q_OBJECT
public:
    yuvoperater();
    ~yuvoperater();

    int Init(QString strFile, AVPixelFormat pixelFmt,quint32 nVideoW, quint32 nVideoH, quint16 nFrameRate = 25);
    void UnInit();
    int play();
    void stopPlay();
    void pusePlay();
    void preFrame();
    void nextFrame();
    void sendProcYuvData(unsigned char *pYUV);
protected:
    void run();

signals:
    void sigOnFrame(QImage img, quint64 nCurFrameIndex, quint64 nTotalFrames);

private:
    bool m_bInit;
    bool m_bRunFlag;
    bool m_bPause;  //播放
    quint32 m_nVideoW;
    quint32 m_nVideoH;
    quint16 m_nFrameRate;
    quint64 m_nCurFrameIndex;
    quint64 m_nTotalFrames;
    QFile m_fileYuv;
    AVFrame* m_pYuvFrame;
    AVFrame* m_pRgbFrame;
    uint8_t* m_pRgbBuffer;
    SwsContext* imgCtx;    
    AVPixelFormat m_nAvpixelFmt;
};

#endif // YUVOPERATER_H
